using IrisGenerator.Common.Core;
using IrisGenerator.Common.Tools;
using IrisGenerator.Common.Core.Projects;
namespace IrisGenerator.Common.Modules
{
    
    
    public partial class ModuleInstance {
        
        private System.Nullable<System.Guid> _modInsId;
        
        private System.Nullable<System.Guid> _modId;
        
        private System.Nullable<System.Guid> _forId;
        
        private System.Nullable<System.Guid> _proId;
        
        private System.Nullable<bool> _modInsGenerate;
        
        private System.Nullable<bool> _modInsAnalyze;
        
        private Formater _formater;
        
        private Module _module;
        
        private Project _project;
        
        private ModuleParameterInstanceCollection _moduleParameterInstanceCollection;
        
        private OptionInstanceCollection _optionInstanceCollection;
        
        public virtual System.Nullable<System.Guid> ModInsId {
            get {
                return _modInsId;
            }
            set {
                _modInsId = value;
            }
        }
        
        public virtual System.Nullable<bool> ModInsGenerate {
            get {
                return _modInsGenerate;
            }
            set {
                _modInsGenerate = value;
            }
        }
        
        public virtual System.Nullable<bool> ModInsAnalyze {
            get {
                return _modInsAnalyze;
            }
            set {
                _modInsAnalyze = value;
            }
        }
        
        public virtual Formater Formater {
            get {
                if ((this._formater == null)) {
                    this._formater = Formater.Load(this._forId);
                }
                return this._formater;
            }
            set {
                _formater = value;
            }
        }
        
        public virtual Module Module {
            get {
                if ((this._module == null)) {
                    this._module = Module.Load(this._modId);
                }
                return this._module;
            }
            set {
                _module = value;
            }
        }
        
        public virtual Project Project {
            get {
                if ((this._project == null)) {
                    this._project = Project.Load(this._proId);
                }
                return this._project;
            }
            set {
                _project = value;
            }
        }
        
        public virtual ModuleParameterInstanceCollection ModuleParameterInstanceCollection {
            get {
                if ((this._moduleParameterInstanceCollection == null)) {
                    _moduleParameterInstanceCollection = ModuleParameterInstance.Select_MODULE_PARAMETER_INSTANCE_By_MOD_INS_ID(this.ModInsId);
                }
                return this._moduleParameterInstanceCollection;
            }
        }
        
        public virtual OptionInstanceCollection OptionInstanceCollection {
            get {
                if ((this._optionInstanceCollection == null)) {
                    _optionInstanceCollection = OptionInstance.Select_OPTION_INSTANCE_By_MOD_INS_ID(this.ModInsId);
                }
                return this._optionInstanceCollection;
            }
        }
        
        private void Clean() {
            this.ModInsId = null;
            this._modId = null;
            this._forId = null;
            this._proId = null;
            this.ModInsGenerate = null;
            this.ModInsAnalyze = null;
            this.Formater = null;
            this.Module = null;
            this.Project = null;
            this._moduleParameterInstanceCollection = null;
            this._optionInstanceCollection = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["MOD_INS_ID"] != System.DBNull.Value)) {
                this.ModInsId = ((System.Nullable<System.Guid>)(dr["MOD_INS_ID"]));
            }
            if ((dr["MOD_ID"] != System.DBNull.Value)) {
                this._modId = ((System.Nullable<System.Guid>)(dr["MOD_ID"]));
            }
            if ((dr["FOR_ID"] != System.DBNull.Value)) {
                this._forId = ((System.Nullable<System.Guid>)(dr["FOR_ID"]));
            }
            if ((dr["PRO_ID"] != System.DBNull.Value)) {
                this._proId = ((System.Nullable<System.Guid>)(dr["PRO_ID"]));
            }
            if ((dr["MOD_INS_GENERATE"] != System.DBNull.Value)) {
                this.ModInsGenerate = ((System.Nullable<bool>)(dr["MOD_INS_GENERATE"]));
            }
            if ((dr["MOD_INS_ANALYZE"] != System.DBNull.Value)) {
                this.ModInsAnalyze = ((System.Nullable<bool>)(dr["MOD_INS_ANALYZE"]));
            }
        }
        
        public static ModuleInstanceCollection Select_MODULE_INSTANCE_By_FOR_ID(System.Nullable<System.Guid> FOR_ID) {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.Select_MODULE_INSTANCE_By_FOR_ID(FOR_ID);
                ModuleInstanceCollection collection = new ModuleInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleInstance obj = new ModuleInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleInstanceCollection Select_MODULE_INSTANCE_By_MOD_ID(System.Nullable<System.Guid> MOD_ID) {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.Select_MODULE_INSTANCE_By_MOD_ID(MOD_ID);
                ModuleInstanceCollection collection = new ModuleInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleInstance obj = new ModuleInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleInstanceCollection Select_MODULE_INSTANCE_By_PRO_ID(System.Nullable<System.Guid> PRO_ID) {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.Select_MODULE_INSTANCE_By_PRO_ID(PRO_ID);
                ModuleInstanceCollection collection = new ModuleInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleInstance obj = new ModuleInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleInstanceCollection GetAll() {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.MODULE_INSTANCE_Select_All();
                ModuleInstanceCollection collection = new ModuleInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        ModuleInstance obj = new ModuleInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ModuleInstance Load(System.Nullable<System.Guid> MOD_INS_ID) {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.MODULE_INSTANCE_Select_One(MOD_INS_ID);
                ModuleInstance obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new ModuleInstance();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                System.Data.DataSet ds = dbo.MODULE_INSTANCE_Select_One(this.ModInsId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                dbo.MODULE_INSTANCE_Insert(this._modId, this._forId, this._proId, this.ModInsGenerate, this.ModInsAnalyze);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                dbo.MODULE_INSTANCE_Delete(this.ModInsId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.ModuleInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.ModuleInstance();
                dbo.MODULE_INSTANCE_Update(this.ModInsId, this._modId, this._forId, this._proId, this.ModInsGenerate, this.ModInsAnalyze);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
